/*
 * src/lexical/scan_buf.c
 * 
 * Harry Wei <harryxiyou@gmail.com> (C) 2012
 *
 * scan buf for words.
 */
#include <stdio.h>
#include <glib.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "cp_ctrl.h"

//static 

int scan_buff2words(struct la *ctrl) {
	g_message("enter func %s", __func__);
	if (NULL == ctrl || NULL == ctrl->buff) {
		g_message("%s -- Parameter error!", __func__);
		return -1;
	}
	int ret = 0;
	char buf[BUF_LEN];
	memset(buf, '\0', BUF_LEN);
	sprintf(buf, "%s", "@@##$$ ");
	gchar **v = NULL;
	v = g_strsplit(ctrl->buff, " ", 0);
	int i = 0;
	int j = 0;
	for ( i = 0; i < g_strv_length(v); i++) {
		if (v[i][0] != 0 && v[i][0] != 9 && v[i][0] != 0x0a) {
			g_message("%d %s", i, v[i]);
			for (j = 0; j < strlen(v[i]); j++) {
				if (v[i][j] != 0x0a && v[i][j] != 0x0d) {
					sprintf(buf, "%s%c", buf, v[i][j]);
				}
			}
			sprintf(buf, "%s%s", buf, " ");
		} else {
			continue;
		}
	}
	sprintf(buf, "%s%s", buf, "@@##$$");
	memset(ctrl->buff, '\0', BUF_LEN);
	g_strlcpy(ctrl->buff, buf, BUF_LEN);
	g_message("%s -- at last:[%s]", __func__, ctrl->buff);
	g_strfreev(v);
	g_message("leave func %s", __func__);
	return 0;
}
